﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MicroarrayDataPresentation
{
    internal partial class ReportForm : Form
    {
        private Report report;

        public ReportForm(Report report)
        {
            InitializeComponent();
            this.report = report;
            this.PopulateReport();
        }

        private void PopulateReport()
        {
            if (this.report == null)
            {
                return;
            }

            this.txtClusteringTime.Text = this.report.TimeForClustering.ToString();
            this.txtMdsTime.Text = this.report.TimeForCalculatingMDS.ToString();
            this.txtMinNumberOfConditions.Text = this.report.MinNumberOfConditions.ToString();
            this.txtMinNumberOfObjects.Text = this.report.MinNumberOfObjects.ToString();
            this.txtNumberOfClusters.Text = this.report.NumberOfClusters.ToString();
            this.txtNumberOfObjects.Text = this.report.TotalNumberOfObjects.ToString();
            this.txtPruningTime.Text = this.report.TimeForPrunning.ToString();
            this.txtTotalTime.Text = this.report.TotalTime.ToString();
            this.txtTrashold.Text = this.report.Trashold.ToString();
            this.richTextBoxClusters.Text = this.GetFormatedReportForBlocks();
        }

        private string GetFormatedReportForBlocks()
        {
            StringBuilder builder = new StringBuilder();
            foreach (KeyValuePair<ClusterSize,int> pair in this.report.ClustersFound)
            {
                builder.Append(pair.Key.ToString());
                for (int i = pair.Key.ToString().Length; i < 35; i++)
                {
                    builder.Append('.');
                }
                builder.AppendFormat("{0} pCluster(s)\n\n", pair.Value);
            }
            return builder.ToString();
        }


        internal Report Report 
        {
            get { return this.report; }
            set
            {
                this.report = value;
                PopulateReport();
            }
        }
    }
}
